﻿
namespace Indeco.G24.Windows.Forms
{
	/// <summary>
	/// abstract TinTucSuKien typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class TinTucSuKienDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<TinTucSuKienDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.TinTucSuKien _currentTinTucSuKien = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxTinTucSuKienDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxTinTucSuKienErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxTinTucSuKienBindingSource;
		
		/// <summary> 
		/// the DGV column associated with the IDTinTucDanhMuc property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDTinTucDanhMucDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDTinTuc property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDTinTucDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.TinTuc> _IDTinTucList;
		
		/// <summary> 
		/// The list of selectable TinTuc
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.TinTuc> IDTinTucList
		{
			get {return this._IDTinTucList;}
			set 
			{
				this._IDTinTucList = value;
				this.uxIDTinTucDataGridViewColumn.DataSource = null;
				this.uxIDTinTucDataGridViewColumn.DataSource = this._IDTinTucList;
			}
		}
		
		private bool _allowNewItemInIDTinTucList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of TinTuc
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDTinTucList
		{
			get { return _allowNewItemInIDTinTucList;}
			set
			{
				this._allowNewItemInIDTinTucList = value;
				this.uxIDTinTucDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.TinTucDanhMuc> _IDTinTucDanhMucList;
		
		/// <summary> 
		/// The list of selectable TinTucDanhMuc
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.TinTucDanhMuc> IDTinTucDanhMucList
		{
			get {return this._IDTinTucDanhMucList;}
			set 
			{
				this._IDTinTucDanhMucList = value;
				this.uxIDTinTucDanhMucDataGridViewColumn.DataSource = null;
				this.uxIDTinTucDanhMucDataGridViewColumn.DataSource = this._IDTinTucDanhMucList;
			}
		}
		
		private bool _allowNewItemInIDTinTucDanhMucList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of TinTucDanhMuc
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDTinTucDanhMucList
		{
			get { return _allowNewItemInIDTinTucDanhMucList;}
			set
			{
				this._allowNewItemInIDTinTucDanhMucList = value;
				this.uxIDTinTucDanhMucDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.TinTucSuKien> _TinTucSuKienList;
				
		/// <summary> 
		/// The list of TinTucSuKien to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.TinTucSuKien> TinTucSuKienList
		{
			get {return this._TinTucSuKienList;}
			set
			{
				this._TinTucSuKienList = value;
				this.uxTinTucSuKienBindingSource.DataSource = null;
				this.uxTinTucSuKienBindingSource.DataSource = value;
				this.uxTinTucSuKienDataGridView.DataSource = null;
				this.uxTinTucSuKienDataGridView.DataSource = this.uxTinTucSuKienBindingSource;				
				//this.uxTinTucSuKienBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxTinTucSuKienBindingSource_ListChanged);
				this.uxTinTucSuKienBindingSource.CurrentItemChanged += new System.EventHandler(OnTinTucSuKienBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnTinTucSuKienBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentTinTucSuKien = uxTinTucSuKienBindingSource.Current as Entities.TinTucSuKien;
			
			if (_currentTinTucSuKien != null)
			{
				_currentTinTucSuKien.Validate();
			}
			//_TinTucSuKien.Validate();
			OnCurrentEntityChanged();
		}

		//void uxTinTucSuKienBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.TinTucSuKien"/> instance.
		/// </summary>
		public Entities.TinTucSuKien SelectedTinTucSuKien
		{
			get {return this._currentTinTucSuKien;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxTinTucSuKienDataGridView.VirtualMode;}
			set
			{
				this.uxTinTucSuKienDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxTinTucSuKienDataGridView.AllowUserToAddRows;}
			set {this.uxTinTucSuKienDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxTinTucSuKienDataGridView.AllowUserToDeleteRows;}
			set {this.uxTinTucSuKienDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxTinTucSuKienDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxTinTucSuKienDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="TinTucSuKienDataGridViewBase"/> class.
		/// </summary>
		public TinTucSuKienDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxTinTucSuKienDataGridView = new System.Windows.Forms.DataGridView();
			this.uxTinTucSuKienBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxTinTucSuKienErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDTinTucDanhMucDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxIDTinTucDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			//this.uxIDTinTucBindingSource = new TinTucBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDTinTucBindingSource)).BeginInit();
			//this.uxIDTinTucDanhMucBindingSource = new TinTucDanhMucBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDTinTucDanhMucBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucSuKienDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucSuKienBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucSuKienErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxTinTucSuKienErrorProvider
			// 
			this.uxTinTucSuKienErrorProvider.ContainerControl = this;
			this.uxTinTucSuKienErrorProvider.DataSource = this.uxTinTucSuKienBindingSource;						
			// 
			// uxTinTucSuKienDataGridView
			// 
			this.uxTinTucSuKienDataGridView.AutoGenerateColumns = false;
			this.uxTinTucSuKienDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxTinTucSuKienDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDTinTucDanhMucDataGridViewColumn,
		this.uxIDTinTucDataGridViewColumn			});
			this.uxTinTucSuKienDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxTinTucSuKienDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxTinTucSuKienDataGridView.Name = "uxTinTucSuKienDataGridView";
			this.uxTinTucSuKienDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxTinTucSuKienDataGridView.TabIndex = 0;	
			this.uxTinTucSuKienDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxTinTucSuKienDataGridView.EnableHeadersVisualStyles = false;
			this.uxTinTucSuKienDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnTinTucSuKienDataGridViewDataError);
			this.uxTinTucSuKienDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnTinTucSuKienDataGridViewCellValueNeeded);
			this.uxTinTucSuKienDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnTinTucSuKienDataGridViewCellValuePushed);
			
			//
			// uxIDTinTucDanhMucDataGridViewColumn
			//
			this.uxIDTinTucDanhMucDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDTinTucDanhMucDataGridViewColumn.DataPropertyName = "IDTinTucDanhMuc";
			this.uxIDTinTucDanhMucDataGridViewColumn.HeaderText = "IDTinTucDanhMuc";
			this.uxIDTinTucDanhMucDataGridViewColumn.Name = "uxIDTinTucDanhMucDataGridViewColumn";
			this.uxIDTinTucDanhMucDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDTinTucDanhMucDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDTinTucDanhMucDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDTinTucDataGridViewColumn
			//
			this.uxIDTinTucDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDTinTucDataGridViewColumn.DataPropertyName = "IDTinTuc";
			this.uxIDTinTucDataGridViewColumn.HeaderText = "IDTinTuc";
			this.uxIDTinTucDataGridViewColumn.Name = "uxIDTinTucDataGridViewColumn";
			this.uxIDTinTucDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDTinTucDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDTinTucDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDTinTucDataGridViewColumn
			//				
			this.uxIDTinTucDataGridViewColumn.DisplayMember = "IDTinTucDanhMuc";	
			this.uxIDTinTucDataGridViewColumn.ValueMember = "IDTinTuc";	
			this.uxIDTinTucDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDTinTucDataGridViewColumn.DataSource = uxIDTinTucBindingSource;				
				
			//
			// uxIDTinTucDanhMucDataGridViewColumn
			//				
			this.uxIDTinTucDanhMucDataGridViewColumn.DisplayMember = "IDTinTucDanhMucCha";	
			this.uxIDTinTucDanhMucDataGridViewColumn.ValueMember = "IDTinTucDanhMuc";	
			this.uxIDTinTucDanhMucDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDTinTucDanhMucDataGridViewColumn.DataSource = uxIDTinTucDanhMucBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxTinTucSuKienDataGridView);
			this.Name = "TinTucSuKienDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDTinTucBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxIDTinTucDanhMucBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucSuKienErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucSuKienDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxTinTucSuKienBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				TinTucSuKienDataGridViewEventArgs args = new TinTucSuKienDataGridViewEventArgs();
				args.TinTucSuKien = _currentTinTucSuKien;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class TinTucSuKienDataGridViewEventArgs : System.EventArgs
		{
			private Entities.TinTucSuKien	_TinTucSuKien;
	
			/// <summary>
			/// the  Entities.TinTucSuKien instance.
			/// </summary>
			public Entities.TinTucSuKien TinTucSuKien
			{
				get { return _TinTucSuKien; }
				set { _TinTucSuKien = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxTinTucSuKienDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnTinTucSuKienDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxTinTucSuKienDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnTinTucSuKienDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxTinTucSuKienDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDTinTucDanhMucDataGridViewColumn":
						e.Value = TinTucSuKienList[e.RowIndex].IDTinTucDanhMuc;
						break;
					case "uxIDTinTucDataGridViewColumn":
						e.Value = TinTucSuKienList[e.RowIndex].IDTinTuc;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxTinTucSuKienDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnTinTucSuKienDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxTinTucSuKienDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDTinTucDanhMucDataGridViewColumn":
						TinTucSuKienList[e.RowIndex].IDTinTucDanhMuc = (System.Guid)e.Value;
						break;
					case "uxIDTinTucDataGridViewColumn":
						TinTucSuKienList[e.RowIndex].IDTinTuc = (System.Guid)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
